package com.example.myapplication;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.myapplication.models.Course;
import com.example.myapplication.network.RetrofitClient;

public class CourseDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_detail);

        int courseId = getIntent().getIntExtra("course_id", 0);
        loadCourseDetail(courseId);
    }

    private void loadCourseDetail(int courseId) {
        RetrofitClient.getInstance().getCourseDetail(courseId, new RetrofitClient.ApiCallback<Course>() {
            @Override
            public void onSuccess(Course course) {
                ImageView ivCourseImage = findViewById(R.id.iv_course_image);
                TextView tvTitle = findViewById(R.id.tv_course_title);
                TextView tvInstructor = findViewById(R.id.tv_instructor);
                TextView tvDifficulty = findViewById(R.id.tv_difficulty);
                TextView tvRating = findViewById(R.id.tv_rating);
                TextView tvDescription = findViewById(R.id.tv_description);

                Glide.with(CourseDetailActivity.this)
                        .load(course.getImageUrl())
                        .into(ivCourseImage);

                tvTitle.setText(course.getTitle());
                tvInstructor.setText("讲师: " + course.getInstructor());
                tvDifficulty.setText("难度: " + course.getDifficulty());
                tvRating.setText("评分: " + course.getRating());
                tvDescription.setText(course.getDescription());
            }

            @Override
            public void onError(String message) {
                Toast.makeText(CourseDetailActivity.this, "加载课程详情失败: " + message, Toast.LENGTH_SHORT).show();
            }
        });
    }
}